﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using Finance.UI.ViewModels;

namespace Finance.UI
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
            this.Loaded +=
                (o, e) =>
                {
                    InitializeContent();
                    InitializeEvents();
                };
        }

        private void InitializeContent()
        {
            this.TodaySummary.CycleContent = DateTime.Today.ToShortDateString();

            var startdate = DateTime.Today.AddDays((-((int)DateTime.Today.DayOfWeek + 6) % 7));
            var enddate = startdate.AddDays(6);
            this.WeeklySummary.CycleContent = string.Format("{0}~{1}", startdate.ToString("MMM-dd"), enddate.ToString("MMM-dd"));

            this.MonthlySummary.CycleContent = DateTime.Today.ToString("MMMM");

            
        }

        private void InitializeEvents()
        {
            this.TodaySummary.Click +=
                (o, e) =>
                {
                    NavigationService.Navigate(new Uri("/PeriodicDetailPage.xaml?period=day", UriKind.RelativeOrAbsolute));
                };
            this.WeeklySummary.Click +=
                (o, e) =>
                {
                    NavigationService.Navigate(new Uri("/PeriodicDetailPage.xaml?period=week", UriKind.RelativeOrAbsolute));
                };
            this.MonthlySummary.Click +=
                (o, e) =>
                {
                    NavigationService.Navigate(new Uri("/PeriodicDetailPage.xaml?period=month", UriKind.RelativeOrAbsolute));
                };
        }

        private void btnCreateNewChargeItem_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/ChargeDetailPage.xaml?operation=" + OperationType.Create, UriKind.RelativeOrAbsolute));
        }

        private void abibAccount_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/AccountSettingPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void abibReport_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/ReportPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void abibBudget_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/BudgetPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void abibSetting_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/AccountSettingPage.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}